package com.shop.cereshop.commons.enums;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @description: 用户搜索类型枚举
 * @author zdd
 * @date 2025/9/3 11:27
 * @version 1.0
 */
public enum SearchTypeEnum {

    // 搜索类型（1-商品,2-店铺,3-购物车）
    PRODUCT(1, "商品"),
    SHOP(2, "店铺"),
    SHOPPING_CART(3, "购物车");

    private final Integer code;
    private final String msg;

    private static final Map<Integer, SearchTypeEnum> CODE_MAP = new HashMap<>();

    static {
        for (SearchTypeEnum status : SearchTypeEnum.values()) {
            CODE_MAP.put(status.getCode(), status);
        }
    }

    SearchTypeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public static String getMsgByCode(Integer code) {
        if (Objects.isNull(code)) {
            return "";
        }
        SearchTypeEnum status = CODE_MAP.get(code);
        return status != null ? status.getMsg() : "";
    }
}
